<template>
  <div class="store">
    <store-header @handleSellerInfo="handleSellerInfo"></store-header>
    <store-nav></store-nav>
    <!-- 包含点餐、评价、商家 三个路由模块 -->
    <div class="content">
      <router-view></router-view>
    </div>
    <shop-car></shop-car>
    <transition name="fade">
      <seller-info
        @handleSellerInfo="handleSellerInfo" v-show="showSeller"
      ></seller-info>
    </transition>
  </div>
</template>

<script>
import axios from 'axios'
import { mapMutations } from 'vuex'
import StoreHeader from './components/Header'
import StoreNav from './components/Nav'
import ShopCar from './components/ShopCar'
import SellerInfo from './components/SellerInfo'
export default {
  name: 'Store',
  components: {
    StoreHeader,
    StoreNav,
    ShopCar,
    SellerInfo
  },
  data () {
    return {
      showSeller: false,
      data: {}
    }
  },
  mounted () {
    this.getSellerInfo()
  },
  methods: {
    getSellerInfo () {
      axios.get('api/data.json').then(this.getSellerInfoSucc)
    },
    getSellerInfoSucc (res) {
      if (res.data) {
        this.data = res.data
        this.getData(this.data)
      }
    },
    ...mapMutations(['getData']),
    handleSellerInfo () {
      this.showSeller = !this.showSeller
    }
  }
}
</script>

<style lang="stylus" scoped>
  @import '~styles/common.styl'
  .fade-enter, .fade-leave-to
    opacity 0
    transform translateY(100%)
  .fade-enter-active, .fade-leave-active
    transition all .4s
  .store
    $posFull()
    display flex
    flex-direction column
    .content
      flex 1
      position relative
      overflow hidden
</style>
